package core;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import core.dijkstra.RoutesMap;

import map.Airport;

public class Graphe implements RoutesMap {
	
	private Hashtable<String, Airport> graph;
	
	public Graphe(Hashtable<String, Airport> graph) {
		this.graph=graph;
	}

	@Override
	public List<Airport> getDestinations(Airport city) {
		return (List<Airport>) graph.get(city.getCode()).getVoisins();
	}

	@Override
	public int getDistance(Airport start, Airport end) {
		// TODO Auto-generated method stub
		return start.distance(end);
	}

	@Override
	public RoutesMap getInverse() {
		// TODO Auto-generated method stub
		return this;
	}

	@Override
	public List<Airport> getPredecessors(Airport city) {
		// TODO Auto-generated method stub
		List<Airport> res = new ArrayList<Airport>();
		Iterator<Airport> itgraph = graph.values().iterator();
		while(itgraph.hasNext()) {
			Airport a = itgraph.next();
			if(a.getVoisins().contains(city)) res.add(a);
		}
		return res;
	}

}
